/* eslint-disable */
import $http from '../utils/http'
import echarts from 'echarts'
import { Notification } from 'AtElement';
import webcount from '../containers/statistics/safePortrait/index/linebar'
import line from '../containers/statistics/safePortrait/index/line'
import radar from '../containers/statistics/safePortrait/index/radar'
import ddline from '../containers/statistics/safePortrait/index/ddline'
import area_basic from '../containers/statistics/safePortrait/index/area_basic'
import circleScore from '../containers/statistics/safePortrait/index/circleScore'
import fontStyleScore from '../containers/statistics/safePortrait/index/fontStyleScore'
import drawCircle from '../containers/statistics/safePortrait/index/alarmCircle'
import areacharts from '../containers/statistics/safePortrait/index/areacharts'

// 函数名
const fastfilter = 'safePortraiat/fastfilter';
const webcompreScore = 'safePortraiat/webcompreScore';
const threatarea = 'safePortraiat/threatarea';
const alarmarea = 'safePortraiat/alarmarea';
const webScore = 'safePortraiat/webScore';
const safescore = 'safePortraiat/safescore';
const scoreranking = 'safePortraiat/scoreranking';
const avgscore = 'safePortraiat/avgscore';
const scoringTrend = 'safePortraiat/scoringTrend';
const newtimewebsite = 'safePortraiat/newtimewebsite';
const getwebmsg = 'safePortraiat/getwebmsg';
// 变量名
const getfastfilter = 'safePortraiat/getfastfilter';
const getwebcompreScore = 'safePortraiat/getwebcompreScore';
const getnewTime = 'safePortraiat/getnewTime'
const getwebnum = 'safePortraiat/getwebnum';
const getthreatarea = 'safePortraiat/getthreatarea';
const getwebScore = 'safePortraiat/getwebScore';
const changewebScore = 'safePortraiat/changewebScore'
const changewebSort = 'safePortraiat/changewebSort'

const getrealrisk = 'safePortraiat/getrealrisk'
const getusability = 'safePortraiat/getusability'
const getoperate = 'safePortraiat/getoperate'
const getriskwarning = 'safePortraiat/getriskwarning'
const gethistorySecurity = 'safePortraiat/gethistorySecurity'
const getscoringrank = 'safePortraiat/getscoringrank'
const getnewtimewebsite = 'safePortraiat/getnewtimewebsite'
const getgetwebmsg = 'safePortraiat/getgetwebmsg'
const getactivetag = 'safePortraiat/getactivetag'
const getwebCount = 'safePortraiat/getwebCount'
const getnodelist = 'safePortraiat/getnodelist'
const getarealist = 'safePortraiat/getarealist'
const safePortraitmsg = {
	state: {
		fastfilterTable: {
			"webtypeFilter": [],
			"belongAreaFilter": [],
			"weblevelFilter": [],
			"newTime": {},
		},
		
		
		// 传的参数
		parameterweblist: {
			pagination: {
				current: 1, // 当前页码
				pageSize: 20 // 当前页显示的数据条数
			},
			search: {
				value: '' // 需要模糊搜索的值（搜索框）
			},
			sorter: {
				field: 'brank', // 排序的字段
				order: 'ascing' // 升序还是降序
			},
			filters: {
				// 需要被过滤的字段
				bwebsite_level: [],
				bbelong_area: [],
				bnode_name:[],
			}
		},
		// 网站综合评分
		tablewebcompreScore: {},
		// 更新时间
		tableNewTime: {},
		tablegetwebnum: 0,
		// 威胁分布
		tablethreatarea: {
			risk_type:[],
			total:[]
		},
		// 区域分布
		tablebelongarea: [],
		// 区域参数
		parambelongarea: {
			sorter: {
				field: 'aall_score', // 排序的字段
				order: 'descend' // 升序还是降序
			},
		},
		// 机构分布
		tablenodeScore: [],
		// 网站评分
		tablewebScore:[],
		paramwebScore: {
			sorter: {
				field: 'aall_score', // 排序的字段
				order: 'descend' // 升序还是降序
			},
			dict:{
				'scoreType':'all_score'
			}
		},
	   // 实时风险
	   tablerealrisk: {
		'attck_event_num': 0,
		'import_attackevent_num':0,
		'step1_assert_num':0,
		'step2_assert_num':0,
		'step3_assert_num':0,
		'step4_assert_num':0,
		'step5_assert_num':0,
		'all_assert_num':0
	   },
	   // 网站运行情况
	   tableusability: {
		usability:{
			'max_node_num': 0 ,
			'min_node_num': 0
		},
		'nowliving_node': 0
	   },
	   // 网站运营情况
	   tableoperate: {},
	   // 风险事项
	   tableriskwarning: [],
	   // 历史评分
	   tablehistorySecurity:{
		   'avg_real_score': 0,
		   'avg_all_handle_score': 0,
		   'avg_warning_score': 0,
		   'avg_run_score': 0,
		   'avg_all_score': 0
	   },
	   // 相关评分和排名
	   tablescoringrank: {
		 'all_score': 0,
		 'all_scorerink': 1,
		 'real_score': 0,
		 'real_scorerink': 1,
		 'usability_score':0,
		 'usability_scorerink': 1,
		 'all_handle_score': 0,
		 'all_handle_scorerink': 1,
		 'warning_score': 0,
		 'warning_scorerink':1,
		 'avg_all_score':0,
		 'avg_all_scorerink': 1
	   },
	   // 网站资源和最新时间
	   tablenewtimewebsite:{},
	   // 获得网站的信息
	   tablewebsitemsg : {},
	   // 动态标签
	   tableactivetag: [],
	   // 网站个数
	   websitenum : 0,
	},
	actions: {
		// 快速筛选
		[fastfilter]({ commit }){
			$http.post('/api/safe/fastfilter').then(({ status, msg, data } = {}) =>{
				if (status === 'success') {
				  commit("safePortraiat/getfastfilter", data)
				} else if(status === 'fail') {
				  Notification.error({
					title: '数据获取异常',
					message: msg
				  })
				}
			  })
		},
		// 网站综合评分
		[webcompreScore]({ commit }){
			$http.post('/api/safe/webcompreScore').then(({ status, msg, data } = {}) =>{
				if (status === 'success') {
					let xdata = data.webNum['name']
					let totaldata = data.webNum['remainder']
					let data1 = data.webNum['total']
					let count = webcount(xdata,totaldata,data1)
					if (document.getElementById('webcount')) {
					let myChart = echarts.init(document.getElementById('webcount'))
					 myChart.setOption(count)
					}
					commit("safePortraiat/getnewTime", data.newTime)
					commit("safePortraiat/getwebcompreScore", data.webScore)
					commit("safePortraiat/getwebnum", data.webNum.total[0])
					let tocolor = []
					if (data.webScore.all_score < 80 ){
						tocolor = [255,200,51] 
					}
					else if(data.webScore.all_score < 60){
						tocolor = [255,153,52] 
					}
					else if(data.webScore.all_score < 40){
						tocolor = [255,102,52] 
					}
					else if(data.webScore.all_score < 20){
						tocolor = [255,51,52] 
					}
					else {
						tocolor = [3,188,120] 
					}
                    fontStyleScore('fontStyle', data.webScore.all_score, tocolor)
					
				} else if(status === 'fail') {
				  Notification.error({
					title: '数据获取异常',
					message: msg
				  })
				}
			  })
		},
		// 威胁分布
		[threatarea]({ commit }){
			$http.post('/api/safe/threatarea').then(({ status, msg, data } = {} ) =>{
				if (status === 'success') {
					commit("safePortraiat/getthreatarea", data)
				} else if(status === 'fail') {
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
				})
		},
		// 告警分布
		[alarmarea](){
			$http.post('/api/safe/alarmarea').then(({ status, msg, data }= {}) =>{
				if (status === 'success') {
					let count = drawCircle(data)
					if (document.getElementById('circle')) {
					let myChart = echarts.init(document.getElementById('circle'))
					 myChart.setOption(count)
					}
				} else if(status === 'fail') {
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
				})
		},
		// 网站评分
		[webScore]({ commit, state }){
			$http.option('/api/safe/webScore', state.paramwebScore).then(({ status, msg, data } = {} ) =>{
				if (status === 'success') {
					commit("safePortraiat/getwebScore", data)
				} else if(status === 'fail') {
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
				})
		},
	   //  评分详情
		[safescore]({ commit }, website_id){
			$http.post('/api/safe/safescore',{'website_id':website_id}).then(({ status, msg, data } = {}) =>{
				if (status === 'success') {
					commit("safePortraiat/getrealrisk", data.riskdata) 
					let linedata = line(data.usability.usability.static_time, data.usability.usability.living_node_num)
					if (document.getElementById('linedd')) {
					let myChart = echarts.init(document.getElementById('linedd'))
					 myChart.setOption(linedata)
					}

					let areadata = areacharts(data.operate.operate24, data.operate.operate48, data.operate.operate72, data.operate.operate73)
					if (document.getElementById('operate')) {
						let myChart = echarts.init(document.getElementById('operate'))
						 myChart.setOption(areadata)
						}
					commit("safePortraiat/getusability", data.usability) 
					commit("safePortraiat/getoperate", data.operate) 
					commit("safePortraiat/getriskwarning", data.riskwarning) 
					commit("safePortraiat/gethistorySecurity", data.historySecurity) 
					commit("safePortraiat/getactivetag", data.realrisk) 
				} else if(status === 'fail') {
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
				})
		},
		// 评分和排名
		[scoreranking]({ commit }, website_id){
			$http.post('/api/safe/scoreranking',{'website_id':website_id}).then(({ status, msg, data } = {}) =>{
				if (status === 'success') {
					commit("safePortraiat/getscoringrank", data.scoringrank)
					commit("safePortraiat/getwebCount", data.websitenum)
					let tocolor = []
					if (data.scoringrank.all_score < 80 ){
						tocolor = [255,200,51] 
					}
					else if(data.scoringrank.all_score < 60){
						tocolor = [255,153,52] 
					}
					else if(data.scoringrank.all_score < 40){
						tocolor = [255,102,52] 
					}
					else if(data.scoringrank.all_score < 20){
						tocolor = [255,51,52] 
					}
					else if(data.scoringrank == null){
						data.scoringrank.all_score = 0
						tocolor = [3,188,120] 
					}
					else {
						tocolor = [3,188,120] 
					}
					
                    circleScore('canvas',data.scoringrank.all_score, tocolor)
					let radardata = radar(data.radar, data.scoringrank.all_score)  
					if (document.getElementById('drawradar')) {
						let myChart = echarts.init(document.getElementById('drawradar'))
						myChart.setOption(radardata)
					  }
				} else if(status === 'fail') {
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
				})
		},
		// 获得最新时间和网站资源
		[newtimewebsite]({ commit },website_id){
			$http.post('/api/safe/newtimewebsite',{'website_id' :website_id}).then(({ status, msg, data } = {}) =>{
				if (status === 'success') {
					commit("safePortraiat/getnewtimewebsite", data)
				} else if(status === 'fail') {
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
				})
		},
		// 安全评分和平均评分的曲线图
		[avgscore]({}, website_id){
			$http.post('/api/safe/avgscore',{'website_id':website_id}).then(({ status, msg, data } = {}) =>{
				if (status === 'success') {
					let linedata = ddline(data.Static_time, data.All_score, data.Avg_all_score)  
					if (document.getElementById('drawddline')) {
						let myChart = echarts.init(document.getElementById('drawddline'))
						myChart.setOption(linedata)
					  }
				} else if(status === 'fail') {
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
				})
		},
		// 安全评分变化趋势
		[scoringTrend]({}, selecttime){
			console.log(selecttime , '时间选择范围')
			$http.post('/api/safe/scoringTrend',{'selectTime':selecttime}).then(({ status, msg, data} = {} ) =>{
				if (status === 'success') {
					let scoretrend = area_basic(data.xdata, data.ydata)  
					if (document.getElementById('scoreTrend')) {
						let myChart = echarts.init(document.getElementById('scoreTrend'))
						myChart.setOption(scoretrend)
						}
				} else if(status === 'fail'){
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
			})
		},
		// 获得网站信息
		[getwebmsg]({ commit }, website_id){
			$http.post('/api/safe/getwebmsg',{'website_id':website_id}).then(({ status, msg, data } = {} ) =>{
				if (status === 'success') {
					commit("safePortraiat/getgetwebmsg", data)
				} else if(status === 'fail') {
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				  }
				})
		},
		
	},
	mutations: {
		[getfastfilter](state, data) {
			state.fastfilterTable = data
		},
		// 网站安全运行情况
		[getwebcompreScore](state, data) {
			state.tablewebcompreScore = data
		},
		[getwebnum](state, data) {
			state.tablegetwebnum = data
		},
		// 威胁分布
		[getthreatarea](state, data) {
			state.tablethreatarea = data
		},
		// 网站评分
		[getwebScore](state, data) {
			state.tablewebScore = data
		},
		// 网站评分
		[changewebScore](state, data) {
			state.paramwebScore.dict.scoreType = data
		},
		// 网站评分排序
		[changewebSort](state, data) {
			state.paramwebScore.sorter.field = data.prop
			state.paramwebScore.sorter.order = data.order
		},
		// 
		[getnewTime](state, data1) {
            state.tableNewTime = data1
		},

		[getrealrisk](state, data) {
            state.tablerealrisk = data
		},
		[getusability](state, data) {
            state.tableusability = data
		},
		[getoperate](state, data) {
            state.tableoperate = data
		},
		[getriskwarning](state, data) {
            state.tableriskwarning = data
		},
		[gethistorySecurity](state, data) {
            state.tablehistorySecurity = data
		},
		[getscoringrank](state, data) {
            state.tablescoringrank = data
		},
		// 获得最新时间和网站资源
		[getnewtimewebsite](state, data) {
            state.tablenewtimewebsite = data
		},
		// 获得网站的信息
		[getgetwebmsg](state, data) {
            state.tablewebsitemsg = data
		},
		// 动态标签
		[getactivetag](state, data) {
            state.tableactivetag = data
		},
		// 网站个数
		[getwebCount](state, data) {
			state.websitenum = data
		},

		// 动态标签
		[getnodelist](state, data) {
            state.nodelisttable = data
		},
		// 网站个数
		[getarealist](state, data) {
			state.arealisttable = data
		},
	}
};

export default safePortraitmsg;
